package ysm.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import ysm.entity.College;
import ysm.entity.Profession;
import ysm.mapper.CollegeMapper;
import ysm.mapper.ProfessionMapper;

@Service
public class ProfessionService {
	
	@Autowired
	private ProfessionMapper professionMapper;
	
	@Autowired
	private CollegeMapper collegeMapper;
	
	public List loadAllProfession() {
		List list = professionMapper.loadAllProfession();
		List result = new ArrayList();
		
		for (int i = 0; i < list.size(); i++) {
			Profession profession = (Profession) list.get(i);
			College college = collegeMapper.selectByPrimaryKey(profession.getCollegeid());
			profession.setCollegename(college.getCollegename());
			result.add(profession);
		}
		return result;
	}
	
	public void deleteByPrimaryKey(Integer id) {
		professionMapper.deleteByPrimaryKey(id);
	};

	public void insert(Profession record) {
		professionMapper.insert(record);
	}

	public void insertSelective(Profession record) {
		professionMapper.insert(record);
	}

	public Profession selectByPrimaryKey(Integer id) {
		Profession profession = professionMapper.selectByPrimaryKey(id);
		College college = collegeMapper.selectByPrimaryKey(profession.getCollegeid());
		profession.setCollegename(college.getCollegename());
		return profession;
	}

	public void updateByPrimaryKeySelective(Profession record) {
 		professionMapper.updateByPrimaryKeySelective(record);
	}

	public void updateByPrimaryKey(Profession record) {
		professionMapper.updateByPrimaryKey(record);
	}
	
	public Profession selectByProfessionname(String professionname) {
		return professionMapper.selectByProfessionname(professionname);
	}

}
